# Set chunk options
knitr::opts_chunk$set(echo = TRUE, warning = FALSE, message = FALSE)
# Load required libraries
library(plotly)
## Loading required package: ggplot2
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
library(htmltools)

# Load the mtcars dataset
data(mtcars)

# Create the interactive plot using Plotly
plot <- plot_ly(mtcars, x = ~hp, y = ~mpg, text = ~paste("Car Model:", rownames(mtcars)), 
                mode = "markers", color = ~factor(cyl), size = ~wt, sizes = c(10, 50),
                marker = list(symbol = "circle", sizemode = "diameter", opacity = 0.7),
                hoverinfo = "text") %>%
  layout(title = "Horsepower vs. Miles per Gallon",
         xaxis = list(title = "Horsepower"),
         yaxis = list(title = "Miles per Gallon"),
         legend = list(title = list(text = "Cylinders")))

# Display the plot
plot
## No trace type specified:
##   Based on info supplied, a 'scatter' trace seems appropriate.
##   Read more about this trace type -> https://plotly.com/r/reference/#scatter
## Warning: `line.width` does not currently support multiple values.
## Warning: `line.width` does not currently support multiple values.
## Warning: `line.width` does not currently support multiple values.